package com.taotao.controller;

import com.taotao.pojo.EasyUIResult;
import com.taotao.pojo.TaotaoResult;
import com.taotao.pojo.TbItem;
import com.taotao.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by new on 2018/5/31.
 */
@Controller
public class ItemController {

    @Autowired
    private ItemService itemService;

    //@PathVariable 从路径中获取参数，如果路径中参数名和接口中参数名一致，则不需要value
    @RequestMapping("/item/{itemId}")
    @ResponseBody
    public TbItem getItemById(@PathVariable Long itemId){
        TbItem tbItem = itemService.getItemById(itemId);
        return tbItem;
    }

    @RequestMapping("/")
    public String index(){
        return "index";
    }

    @RequestMapping("/item-list")
    public String itemList(){
        return "item-list";
    }

    @RequestMapping("/item-add")
    public String itemCatList(){
        return "item-add";
    }

    @RequestMapping("/item-param-list")
    public String itemParamList(){
        return "item-param-list";
    }

    @RequestMapping("/item-param-add")
    public String itemParamAdd(){
        return "item-param-add";
    }

    @RequestMapping("/content-category")
    public String contentCategory(){
        return "content-category";
    }

    @RequestMapping("/content")
    public String content(){
        return "content";
    }

    @RequestMapping("/content-add")
    public String contentAdd(){
        return "content-add";
    }

    @RequestMapping("/item/list")
    @ResponseBody
    public EasyUIResult getItemList(Integer page,Integer rows){
        if(page == null){
            page = 1;
        }
        if(rows == null){
            rows = 20;
        }
        EasyUIResult itemList = itemService.getItemList(page, rows);
        return itemList;
    }

    @RequestMapping(value = "/item/save",method = RequestMethod.POST)
    @ResponseBody
    public TaotaoResult createItem(TbItem item,String desc,String itemParams) throws Exception{
        TaotaoResult result = itemService.createItem(item,desc,itemParams);
        return result;
    }
}
